<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="商品分类" prop="typeId">
        <el-select
          v-model="queryParams.typeId"
          placeholder="请选择商品分类"
          clearable
          size="small"
        >
          <el-option
            v-for="item in productTypeList"
            :key="item.id"
            :label="item.typeName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商品编号" prop="productSn">
        <el-input
          v-model="queryParams.productSn"
          placeholder="请输入商品编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品条形码" prop="productBarcode">
        <el-input
          v-model="queryParams.productBarcode"
          placeholder="请输入商品条形码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入供应商名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌名称" prop="brandName">
        <el-input v-model="queryParams.brandName" placeholder="请输入品牌名称">
          <el-button slot="append" icon="el-icon-thumb" @click="queryBrand()"
            >选择</el-button
          >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['supplier:product:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['supplier:product:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['supplier:product:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['supplier:product:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="productList"
      @selection-change="handleSelectionChange"
      :default-sort="{ prop: 'productSort', order: 'ascending' }"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template slot-scope="scope">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="商品分类">
              <span>{{ scope.row.typeName }}</span>
            </el-form-item>
            <el-form-item label="商品编号">
              <span>{{ scope.row.productSn }}</span>
            </el-form-item>
            <el-form-item label="商品名称">
              <span>{{ scope.row.productName }}</span>
            </el-form-item>
            <el-form-item label="供应商名称">
              <span>{{ scope.row.supplierName }}</span>
            </el-form-item>
            <el-form-item label="品牌名称">
              <span>{{ scope.row.brandName }}</span>
            </el-form-item>
            <el-form-item label="保质期限" >
              <span>{{ scope.row.shelfLife }} {{lifeTypeFormat(scope.row)}}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="商品编号" align="center" prop="productSn" />
      <el-table-column label="商品条形码" align="center" prop="productBarcode" />
      <el-table-column
        label="商品分类"
        align="center"
        prop="typeId"
        :formatter="productTypeFormat"
      />
     
      <el-table-column label="商品名称" align="center" prop="productName" />
      <el-table-column label="供应商名称" align="center" prop="supplierName" />
      <el-table-column label="品牌名称" align="center" prop="brandName" />
      <!-- <el-table-column label="商品图片" align="center" prop="picture" /> -->
      <el-table-column
        label="计量单位"
        align="center"
        prop="measurement"
        :formatter="measurementFormat"
      />
      <el-table-column
        label="商品排序"
        align="center"
        prop="productSort"
        sortable
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAttribute(scope.row)"
            v-hasPermi="['supplier:product:attribute']"
            >价格设置</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['supplier:product:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['supplier:product:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="520px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="95px">
        <el-row :gutter="0">
          <el-col :span="24">
            <el-form-item label="商品分类" prop="typeId">
              <el-input
                v-model="form.typeName"
                placeholder="请选择商品分类"
                :readonly="true"
              >
                <el-button
                  slot="append"
                  icon="el-icon-thumb"
                  @click="queryProductType()"
                  >选择</el-button
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="商品编号" prop="productSn">
              <el-input
                v-model="form.productSn"
                placeholder="请输入商品编号"
                clearable
                maxlength="30"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="商品条形码" prop="productBarcode">
              <el-input
                v-model="form.productBarcode"
                placeholder="请输入商品条形码"
                clearable
                maxlength="60"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="商品名称" prop="productName">
              <el-input
                v-model="form.productName"
                placeholder="请输入商品名称"
                maxlength="30"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="供应商名称" prop="supplierName">
                <supplier-input
                  ref="supplierParams"
                  :supplier-props.sync="supplierData"
                  v-model="form.supplierName"
                />
        </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="品牌名称" prop="brandName">
              <el-input v-model="form.brandName" placeholder="请选择品牌名称">
                <el-button
                  slot="append"
                  icon="el-icon-thumb"
                  @click="queryBrand()"
                  >选择</el-button
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保质期限" prop="shelfLife">
              <el-input-number
                v-model="form.shelfLife"
                placeholder="请输入保质期限"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="" prop="shelfLifeType">
              <el-select
                v-model="form.shelfLifeType"
                placeholder="请选择年月日"
                clearable
              >
                <el-option
                  v-for="dict in lifeTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="计量单位" prop="measurement">
              <el-select
                v-model="form.measurement"
                placeholder="请选择计量单位"
              >
                <el-option
                  v-for="dict in measurementOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="商品排序" prop="productSort">
              <el-input-number
                v-model="form.productSort"
                placeholder="请输入商品排序"
                :min="1"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                maxlength="250"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加品牌对话框 -->
    <el-dialog :visible.sync="addVisiable" title="添加品牌" append-to-body>
      <div class="search">
        <el-input
          v-model="listQuery.brandDesc"
          clearable
          class="filter-item"
          style="width: 200px"
          placeholder="请输入品牌名称"
        />
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
          >查找</el-button
        >
        <el-table
          v-loading="loading"
          :data="brandList"
          element-loading-text="正在查询中。。。"
          border
          fit
          highlight-current-row
        >
          <!-- <el-table-column label="" width="65">
            <template slot-scope="scope">
              <el-radio class="radio" v-model="templateSelection" :label="scope.$index">&nbsp;</el-radio>
            </template>
          </el-table-column> -->

          <el-table-column align="center" label="品牌ID" prop="id" />
          <el-table-column align="center" label="品牌名称" prop="brandDesc" />
          <el-table-column align="center" label="品牌排序" prop="brandSort" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="confirmAdd(scope.row)"
                >选择</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery.pageNum"
          :limit.sync="listQuery.pageSize"
          @pagination="getBrandList"
        />
      </div>
    </el-dialog>

    <!-- 添加商品分类对话框 -->
    <el-dialog :visible.sync="addVisiableType" title="商品分类">
      <div class="search">
        <el-input
          v-model="listQueryType.typeName"
          clearable
          class="filter-item"
          style="width: 200px"
          placeholder="请输入商品分类名称"
        />
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilterType"
          >查找</el-button
        >
        <el-table
          v-loading="loading"
          :data="productTypeList"
          element-loading-text="正在查询中。。。"
          border
          fit
          highlight-current-row
        >
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="confirmAddType(scope.row)"
                >选择</el-button
              >
            </template>
          </el-table-column>
          <el-table-column label="类型排序" align="center" prop="typeSort" />
          <el-table-column
            label="类型名称"
            align="center"
            prop="typeName"
            min-width="150px"
          />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQueryType.pageNum"
          :limit.sync="listQueryType.pageSize"
          @pagination="getProductTypeList"
        />
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="addVisiablePrice"
      title="价格设置"
      :fullscreen="true"
      append-to-body
    >
      <el-form
        ref="priceList"
        :model="formAttribute"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="商品分类" prop="typeId">
          <el-input v-model="formAttribute.typeName" :readonly="true" />
        </el-form-item>

        <el-form-item label="商品名称" prop="productName">
          <el-input v-model="formAttribute.productName" :readonly="true" />
        </el-form-item>

        <el-form-item label="商品规格">
          
          <div v-for="(item, index) in productSpecList" :key="index">
            <el-row :gutter="5">
              <el-col :span="2">
                <span>{{ item.specName }}</span>
              </el-col>
              <el-checkbox-group v-model="productSpecItemCheckBox">
                <div
                  v-for="(itemSpec, index) in productSpecItemList"
                  :key="index"
                >
                  <el-col :span="2" v-if="item.id === itemSpec.specId">
                    <el-checkbox
                      :label="itemSpec.itemName"
                      :checked="true"
                      :disabled="true"
                    ></el-checkbox>
                  </el-col>
                </div>
              </el-checkbox-group>
             
            </el-row>
          </div>

          <el-table :data="priceList" border>
            <el-table-column
              prop="itemName"
              fixed
              label="规格"
            ></el-table-column>
            <el-table-column prop="referencePrice" label="参考单价(元)">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.referencePrice"
                  :precision="2"
                  :step="0.1"
                  placeholder="请输入参考单价" controls-position="right"
                >
                </el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="price" label="进货价(元)">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.price"
                  :precision="2"
                  :step="0.1"
                  placeholder="请输入进货价" controls-position="right"
                >
                </el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="memberPrice" label="会员价(元)">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.memberPrice"
                  :precision="2"
                  :step="0.1"
                  placeholder="请输入会员价" controls-position="right"
                >
                </el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="marketPrice" label="零售价(元)">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.marketPrice"
                  :precision="2"
                  :step="0.1"
                  placeholder="请输入零售价" controls-position="right"
                ></el-input-number>
              </template>
            </el-table-column>
            
          </el-table>
        </el-form-item>
        <el-form-item label="更新数据">
           <el-button type="warning" @click="updatePrice" size="mini" round>更新</el-button>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormPrice">确 定</el-button>
        
        <el-button @click="cancelAttribute">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>

<script>
import {
  listProduct,
  getProduct,
  delProduct,
  addProduct,
  updateProduct,
  exportProduct,
} from "@/api/supplier/product";
import { listBrand } from "@/api/supplier/brand";
import { listProductType } from "@/api/supplier/productType";
import { listProductSpecByTypeId } from "@/api/supplier/productSpec";
import { listProductSpecItemByTypeId } from "@/api/supplier/productSpecItem";
import { listPriceProduct, updatePriceBatch,updatePriceSet } from "@/api/supplier/price";
import supplierInput from "@/views/supplier/supplier/input";


export default {
  name: "Product",
  components: {
    supplierInput,
    },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  data() {
    return {
      isCollapse: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品表格数据
      productList: [],

      // 商品规格数据
      productSpecList: [],

      // 商品规格明细数据
      productSpecItemList: [],

      // checkBox 选中值
      productSpecItemCheckBox: [],

      // 价格表
      priceList: [],

      isChecked: false,

      // 商品分类表格数据
      productTypeList: [],
      supplierData: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      filterText: "",
      // 弹出层标题
      title: "",
      // 品牌表格数据
      brandList: [],
      // 默认隐藏品牌对话框
      addVisiable: false,
      addVisiablePrice: false,
      addVisiableType: false,
      // 是否显示弹出层
      open: false,
      // 计量单位字典
      measurementOptions: [],
      // 保质期限年月日字典
      lifeTypeOptions: [],
      listQuery: {
        pageNum: 1,
        pageSize: 5,
      },
      listQueryType: {
        pageNum: 1,
        pageSize: 10,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productSn: null,
        productName: null,
        productBarcode: null,
        origin: null,
        brandId: null,
        brandName: null,
        picture: null,
        measurement: null,
        productSort: null,
        orderByColumn: "productSort",
        isAsc: "asc"
      },
      // 表单参数
      form: {},

      // 价格表单参数
      formPrice: {},

      formAttribute: {},
      // 表单校验
      rules: {
        typeId: [
          {
            required: true,
            message: "商品分类不能为空",
          },
        ],

        productSn: [
          {
            required: true,
            message: "商品编号不能为空",
          },
        ],

        productName: [
          {
            required: true,
            message: "商品名称不能为空",
          },
        ],

        supplierName: [
          {
            required: true,
            message: "供应商不能为空",
          },
        ],

        brandName: [
          {
            required: true,
            message: "品牌名称不能为空",
          },
        ],

      },
    };
  },
  created() {
    this.getList();
    this.getDicts("bus_measurement").then((response) => {
      this.measurementOptions = response.data;
    });
    this.getDicts("bus_life_type").then((response) => {
      this.lifeTypeOptions = response.data;
    });
    listProductType().then((response) => {
      this.productTypeList = response.rows;
    });
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    /** 查询品牌列表 */
    getBrandList() {
      this.loading = true;
      listBrand(this.listQuery).then((response) => {
        this.brandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询商品分类列表 */
    getProductTypeList() {
      this.loading = true;
      listProductType(this.listQueryType).then((response) => {
        this.productTypeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 选择对应品牌 */
    confirmAdd(row) {
      this.form.brandId = row.id;
      this.addVisiable = false;
      this.form.brandName = row.brandDesc;
      this.queryParams.brandName = row.brandDesc;
    },

    /** 选择对应商品分类 */
    confirmAddType(row) {
      this.formAttribute.typeName = row.typeName;
      this.formAttribute.typeId = row.id;
      this.form.typeId = row.id;
      this.form.typeName = row.typeName;

      this.addVisiableType = false;
    },
    // 商品分类
    queryProductType() {
      this.addVisiableType = true;
    },

    /** 查询商品列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then((response) => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 计量单位字典翻译
    measurementFormat(row, column) {
      return this.selectDictLabel(this.measurementOptions, row.measurement);
    },
    // 保质日期 年月日
    lifeTypeFormat(row, column) {
      
      return this.selectDictLabel(this.lifeTypeOptions, row.shelfLifeType);
    },
    // 取消按钮
    cancelAttribute() {
      this.addVisiablePrice = false;
      this.reset();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    handleFilter() {
      this.listQuery.pageNum = 1;
      this.getBrandList();
    },
    handleFilterType() {
      this.listQueryType.pageNum = 1;
      this.getProductTypeList();
    },

    queryBrand() {
      this.listQuery = {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        brandDesc: undefined,
        sort: "brand_sort",
        order: "asc",
      };
      this.getBrandList();
      this.list = [];
      this.total = 0;
      this.addVisiable = true;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productSn: null,
        productName: null,
        origin: null,
        brandId: null,
        brandName: null,
        picture: null,
        measurement: null,
        productSort: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.supplierData.supplierName = null;

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.supplierData.supplierName = null;

      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品";
      this.supplierData.supplierName = null;
      if(this.$refs.supplierParams!=undefined){
          this.$refs.supplierParams.scName= null;
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getProduct(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.supplierData.supplierName = this.form.supplierName;

        if(this.$refs.supplierParams!=undefined){
            this.$refs.supplierParams.scName= this.form.supplierName;
        }
        this.title = "修改商品";
      });
    },
    /** 修改按钮操作 */
    handleAttribute(row) {
      this.reset();
      const id = row.id || this.ids;
      getProduct(id).then((response) => {
        this.formAttribute = response.data;
        this.addVisiablePrice = true;
      });

      listProductSpecByTypeId(row.typeId).then((response) => {
        this.productSpecList = response.rows;
      });
      listProductSpecItemByTypeId(row.typeId).then((response) => {
        this.productSpecItemList = response.rows;
      });

      let query = {
        productId: id,
      };
      listPriceProduct(query).then((response) => {
        this.priceList = response.rows;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateProduct(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProduct(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交价格设置 */
    submitFormPrice() {
      this.$refs["priceList"].validate((valid) => {
        if (valid) {
          updatePriceBatch(this.priceList).then((response) => {
            this.msgSuccess("修改成功");
            this.addVisiablePrice = false;
            this.getList();
          });
        }
      });
    },
    updatePrice(){
        this.$refs["priceList"].validate((valid) => {
        if (valid) {

          updatePriceSet(this.formAttribute).then((response) =>{
           
            if( this.priceList.length==response.data){
                this.msgError("已经是最新的商品规格!");
                return;
            }
      
            let query = {
              productId: this.formAttribute.id,
            };
            listPriceProduct(query).then((response) => {
              this.priceList = response.rows;
              this.msgSuccess("更新成功");
            });
          });

        }
      });
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除商品编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delProduct(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有商品数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportProduct(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },

    productTypeFormat(row, column) {
      let datas = this.productTypeList;
      let value = row.typeId;
      var actions = [];
      Object.keys(datas).some((key) => {
        if (datas[key].id == "" + value) {
          actions.push(datas[key].typeName);
          return true;
        }
      });
      return actions.join("");
    },
  },
};
</script>
